package collection;

public class Person {
    private String name;
    private int age;
    public Person(String name,int age){
        this.name=name;
        this.age=age;
    }
    public String getName(){
        return name;
    }
    public int getAge(){
        return age;
    }
    public void setName(String name){
        this.name=name;
    }
    public void setAge(int age){
        this.age=age;
    }
    @Override
    public int hashCode(){
        System.out.println("hashCode:"+this.name);
            return this.name.hashCode()+age*37;

    }
    @Override
    public boolean equals(Object obj){
        System.out.println(this+"equals"+obj);
        if (obj instanceof Person){
            Person p= (Person) obj;
            return this.name.equals(p.name)&&this.age==p.age;
        }else {
            return false;
        }
    }


    public String toString(){
        return "Person@name:"+this.name+"age:"+this.age;
    }


//    public static void main(String[] args) {
//        Pet[] a={new Pet("Kurt","艾一"),
//                new RobotPet("R2D2","卢克"),
//                new Pet("迈克尔","英男"),};
////        Pet b=
//
//       // Pet c=
//
//        for (int i = 0; i <a.length ; i++) {
//            if (a[i] instanceof RobotPet)//判断a[i]里是、到底是不是机器狗
//                ((RobotPet)a[i]).work(0);
//            else
//                a[i].introduce();
//        }
//    }


}


